package com.itheima.app.controller;

import com.itheima.app.manager.UserLikeManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserLikeController {

    @Autowired
    private UserLikeManager userLikeManager;

    // 喜欢
    @GetMapping("/tanhua/{id}/love")
    public void tanhuaLove(@PathVariable("id") Long userLikeId) {
        // 调用manager
        userLikeManager.tanhuaLove(userLikeId);
    }

    // 不喜欢
    @GetMapping("/tanhua/{id}/unlove")
    public void tanhuaUnlove(@PathVariable("id") Long userLikeId) {
        // 调用manager
        userLikeManager.tanhuaUnlove(userLikeId);
    }

    // 统计数量
    @GetMapping("/users/counts")
    public ResponseEntity userCounts() {
        // 调用manager
        return userLikeManager.userCounts();
    }

    // 统计详情
    @GetMapping("/users/friends/{type}")
    public ResponseEntity userLikeVoDetail(@PathVariable Integer type,
                                           @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                           @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        // 调用manager
        return userLikeManager.userLikeVoDetail(type, pageNum, pageSize);
    }

    // 粉丝-喜欢
    @PostMapping("/users/fans/{id}")
    public void fansLike(@PathVariable("id") Long fanId) {
        // 调用manager
        userLikeManager.tanhuaLove(fanId);
    }

    // 取消喜欢
    @DeleteMapping("/users/like/{id}")
    public void deleteLike(@PathVariable("id") Long userLikeId){
        // 调用manager
        userLikeManager.tanhuaUnlove(userLikeId);
    }
}
